<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	    xmlns:f="http://java.sun.com/jsf/core"
	    xmlns:h="http://java.sun.com/jsf/html"
	    xmlns:ui="http://java.sun.com/jsf/facelets"
	    xmlns:p="http://primefaces.org/ui"
	    template="/template/template.xhtml">
    
   	<ui:param name="pageTitle" value="Cadastro de Edital" />
   	
    <ui:define name="body"> 
    	<p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>  
              
		<p:dialog modal="true" widgetVar="statusDialog" header="Carregando..."   
		        draggable="false" closable="false">  
		    <p:graphicImage value="/resources/images/ajaxloadingbar.gif" />  
		</p:dialog>  
    	<h:form id="formEdital">
    			<p:growl id="msgsEdital"/>  
				    <p:panelGrid id="cadastro" columns="2" styleClass="cdtEdital" style="float:left;"> 
				     
					    <f:facet name="header">  
					        Cadastro de Edital  
					    </f:facet>  
					  
					    <p:outputLabel for="nome" value="Nome: " /> 
			            <p:inputText id="nome" value="#{editalController.edital.nome}" 
			            					   required="true" 
			            					   label="nome"
			            					   requiredMessage="Por favor, digite o nome do edital."
			            					   maxlength="25"
			            					   size="20"
			            					   >  				   
			            </p:inputText>
			            
			            <p:outputLabel for="contrato" value="Contrato: " /> 
			            <p:inputText id="contrato" value="#{editalController.edital.contrato}" 
			            					   required="true" 
			            					   label="contrato"
			            					   requiredMessage="Por favor, digite o contrato do edital."
			            					   maxlength="25"
			            					   size="20"
			            					   >  				   
			            </p:inputText>
			            			             
			            <p:outputLabel for="popupButtonCal" value="Data Final: " /> 
			            <p:calendar value="#{editalController.edital.dataFim}" size="15" effect="drop" locale="pt" id="popupButtonCal" showOn="button" /> 
			            
			            <p:outputLabel for="preco_inicial" value="Pre&ccedil;o Inicial: " /> 
			            <p:inputText id="preco_inicial" value="#{editalController.edital.precoInicial}" 
			            					   required="true" 
			            					   label="preco_inicial"
			            					   requiredMessage="Por favor, digite o pre&ccedil;o inicial."
			            					   maxlength="16"
			            					   size="20"
			            					   styleClass="precoInicial"
			            					   converter="precoConverter"
			            					   onfocus="$('.precoInicial').maskMoney({showSymbol:true, symbol:'R$',thousands:'.', decimal:','});"
			            					   >  				   
			            </p:inputText>
			            
			            <p:outputLabel for="quantidade" value="Quantidade: " />  
			            <p:spinner id="quantidade"   
                    			   value="#{editalController.edital.quantidade}"
                    			   label="quantidade"
                    			   required="true"
                    			   requiredMessage="Por favor, selecione uma quantidade."
                    			   min="1"
                    			   max="10000"
                    			   maxlength="5"
                    			   size="18" 
                    			   /> 	            
			            <p:outputLabel for="descricao" value="Descri&ccedil;&atilde;o: " />
			            <p:editor id="descricao" value="#{editalController.edital.descricao}" 
			            					  width="200"
			            					  height="200"
			            					  required="true"
			            					  requiredMessage="Por favor, digite uma descri&ccedil;&atilde;o"
			            					  controls="bold italic | font size "/>
			            <p:outputLabel for="cbProduto" value="Produto: " />					  
			            <p:selectOneMenu id="cbProduto" value="#{editalController.edital.produto}" style="width:200px;" rendered="#{editalController.btProduto == false}">  
			                <f:selectItem itemLabel="Selecione um Produto" itemValue="0" />  
			                <f:selectItems value="#{editalController.produtos}"
					    				   var="_produto" 
					    				   itemValue="#{_produto}"
					    				   itemLabel="#{_produto.nome}"  />
			            </p:selectOneMenu>
			            <p:inputText id="produto" value="#{editalController.edital.produto.nome}" 
			            					   readonly="true"
			            					   rendered="#{editalController.btProduto == true}"
			            					   >  		   
			            </p:inputText>
			            
			              
					    <f:facet name="footer">  
					    <p:commandButton value="Cadastrar" 
					    					 update=":formEdital:editais, :formEdital:cadastro, :formEdital:msgsEdital, @parent"  
                							 action="#{editalController.salvar}"   
                							 id="btnGlobal"
                							 icon="ui-icon-check"
                							 rendered="#{editalController.btCadastro == true}">
	                			<p:collector value="#{editalController.edital}"   
	                            			 addTo="#{editalController.editais}" />
                			</p:commandButton>
              					<p:commandButton value="Salvar" 
					    					 update=":formEdital:editais, :formEdital:cadastro, :formEdital:msgsEdital, @parent" 
                							 action="#{editalController.alterarEdital()}"
                							 id="btnGlobalSalvar"
                							 icon="ui-icon-check"
                							 rendered="#{editalController.btSalvar == true}"
                							  />
                			<p:commandButton value="Cancelar" 
                							 update="cadastro" 
                							 process="@this" 
                							 icon="ui-icon-cancel"
                							 actionListener="#{editalController.limpar}"
                							  />
					    </f:facet>  
					</p:panelGrid> 
					<p:outputPanel id="editais">
				     	<p:dataTable id="tbEdital" 
				     				 var="_edital" 
				     				 value="#{editalController.editais}" 
				     				 style="float:left;margin-left:10px;"
				     				 emptyMessage="Nenhum edital cadastrado."
				     				 editable="true"
				     				 paginator="true" rows="5"  
                            		 paginatorTemplate="{PageLinks}"
				     				 selection="#{editalController.selecionado}" selectionMode="single"  
		                             rowKey="#{_edital.idEdital}"
		                             
				     				 >
				     		<p:ajax event="rowSelect" listener="#{editalController.onRowSelect}" update=":formEdital:cadastro"/>				 
			     			
			     			<p:growl id="msgstb"/>		 
			     			<f:facet name="header">  
				            	Editais Cadastrados
					        </f:facet>  
					  
					        <p:column headerText="Nome" width="90">
					            	<h:outputText value="#{_edital.nome}" />
					        </p:column>
					        
					        <p:column headerText="Contrato" width="50">
					            	<h:outputText value="#{_edital.contrato}" />
					        </p:column>
					        
					        <p:column headerText="Data Fim" width="20">
					            	<h:outputText value="#{_edital.dataFim}" />
					        </p:column>
					        
					        <p:column headerText="Pre&ccedil;o" width="40">
					            	<h:outputText value="R$ #{_edital.precoInicial} " />
					        </p:column>
					        
					        <p:column headerText="Ativo" width="40">
					            	<h:outputText rendered="#{_edital.status == false}" value="N&atilde;o" /> 
					            	<h:outputText rendered="#{_edital.status == true}" value="Sim" />  
					        </p:column>    
					        
					        					  
					        <f:facet name="footer"> 
					        <p:commandButton id="selectButton" 
				                				 update=":formEdital:displayEdital" 
				                				 oncomplete="editalDialog.show();" 
				                				 icon="ui-icon-search" 
				                				 title="Ver Detalhes"
				                				 value="Ver Detalhes">  
					                <f:setPropertyActionListener value="#{_edital}" 
					                							 target="#{editalController.selecionado}"
																 />  
					            </p:commandButton> 
					            <p:commandButton 
					            			   title="Inativar Edital"
					            			   value="Inativar Edital"
					            			   update=":formEdital:editais,:formEdital:msgsEdital, @parent" 
					            			   process=":formEdital:editais"
					            			   action="#{editalController.inativarEdital()}"
					            			   icon="ui-icon-trash"
					            			   >  
				                    <p:collector value="#{_edital}"  
				                                 removeFrom="#{editalController.editais}" />  
				                </p:commandButton> 
					        </f:facet>  
					    </p:dataTable>
					    
					</p:outputPanel>  
					
					<p:dialog header="Detalhes do Edital" 
					    		  widgetVar="editalDialog" 
					    		  resizable="false" 
					    		  id="editalDialog"  
                				  showEffect="fade" 
                				  hideEffect="explode" modal="true">  
  
					        <h:panelGrid id="displayEdital" columns="2" cellpadding="4" style="margin:0 auto;">  
					  
					            <f:facet name="header">  
					                 
					            </f:facet>  
					            
					            <h:outputText value="Ativo" />  
					            <h:outputText rendered="#{editalController.edital.status == false}" value="N&atilde;o" style="font-weight:bold" /> 
					            <h:outputText rendered="#{editalController.edital.status == true}" value="Sim" style="font-weight:bold" />  
					  
					            <h:outputText value="Nome" />  
					            <h:outputText value="#{editalController.edital.nome}" style="font-weight:bold"/>
					            
					            <h:outputText value="Contrato" />  
					            <h:outputText value="#{editalController.edital.contrato}" style="font-weight:bold"/>
					            
					            <h:outputText value="Data Final" />  
					            <h:outputText value="#{editalController.edital.dataFim}" style="font-weight:bold"/>
					            
					            <h:outputText value="Pre&ccedil;o Inicial" />  
					            <h:outputText value="#{editalController.edital.precoInicial}" style="font-weight:bold"/> 
					            
					            <h:outputText value="Quantidade:" />  
					            <h:outputText value="#{editalController.edital.quantidade}" style="font-weight:bold"/> 
					            
					            <h:outputText value="Descri&ccedil;&atilde;o:" />  
					            <h:outputText value="#{editalController.edital.descricao}" style="font-weight:bold"/>
					            
					        </h:panelGrid>  
					  
					    </p:dialog> 
			</h:form>
			
    </ui:define>
</ui:composition>